using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region Role

	/// <summary>
	/// Role object for NHibernate mapped table 'Role'.
	/// </summary>
	[Serializable]
	public class Role : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _roleName;
		protected string _description;
		protected bool _isEnabled;
		protected bool _isLeader;
		protected string _cODOrOCO;
		protected IList _flowMembers;
		protected IList _userRoles;
		protected IList _roleIdAssignmentDefinations;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Role() { }

		public Role( string roleName, string description, bool isEnabled, bool isLeader, string cODOrOCO )
		{
			this._roleName = roleName;
			this._description = description;
			this._isEnabled = isEnabled;
			this._isLeader = isLeader;
			this._cODOrOCO = cODOrOCO;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string RoleName
		{
			get { return _roleName; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for RoleName", value, value.ToString());
				_roleName = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public bool IsEnabled
		{
			get { return _isEnabled; }
			set { _isEnabled = value; }
		}

		public bool IsLeader
		{
			get { return _isLeader; }
			set { _isLeader = value; }
		}

		public string CODOrOCO
		{
			get { return _cODOrOCO; }
			set
			{
				if ( value != null && value.Length > 5)
					throw new ArgumentOutOfRangeException("Invalid value for CODOrOCO", value, value.ToString());
				_cODOrOCO = value;
			}
		}

		public IList FlowMembers
		{
			get
			{
				if (_flowMembers==null)
				{
					_flowMembers = new ArrayList();
				}
				return _flowMembers;
			}
			set { _flowMembers = value; }
		}

		public IList UserRoles
		{
			get
			{
				if (_userRoles==null)
				{
					_userRoles = new ArrayList();
				}
				return _userRoles;
			}
			set { _userRoles = value; }
		}

		public IList RoleIdAssignmentDefinations
		{
			get
			{
				if (_roleIdAssignmentDefinations==null)
				{
					_roleIdAssignmentDefinations = new ArrayList();
				}
				return _roleIdAssignmentDefinations;
			}
			set { _roleIdAssignmentDefinations = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is Role))
				throw new InvalidCastException("This object is not of type Role");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Role)obj).Id);
					break;
				case "RoleName":
						relativeValue = ( this.RoleName != null ) ? this.RoleName.CompareTo(((Role)obj).RoleName) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((Role)obj).Description) : -1;
					break;
				case "IsEnabled":
					relativeValue = this.IsEnabled.CompareTo(((Role)obj).IsEnabled);
					break;
				case "IsLeader":
						relativeValue = ( this.IsLeader != Convert.ToBoolean( null) ) ? this.IsLeader.CompareTo(((Role)obj).IsLeader) : -1;				
					break;
				case "CODOrOCO":
						relativeValue = ( this.CODOrOCO != null ) ? this.CODOrOCO.CompareTo(((Role)obj).CODOrOCO) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (Role.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
